package com.turtle3d.user.visualizators;

import java.util.ArrayList;

import javax.media.j3d.Appearance;
import javax.media.j3d.BranchGroup;
import javax.media.j3d.Material;
import javax.media.j3d.Shape3D;
import javax.vecmath.Color3f;
import javax.vecmath.Matrix4f;

import com.turtle3d.ResourceManager;
import com.turtle3d.formallanguage.VisualSymbol;
import com.turtle3d.formallanguage.symbol.Symbol;
import com.turtle3d.visualizator.VisualData;
import com.turtle3d.visualizator.Visualizator;

public class SpongeBox extends Visualizator {

	@Override
	public BranchGroup visualize(VisualData visualData) {

		BranchGroup branchGroup = new BranchGroup();

		ArrayList<VisualSymbol> visualSequence = visualData.getVisualSequence();

		for (int i = 0; i < visualSequence.size(); i++) {

			VisualSymbol visualSymbol = visualSequence.get(i);

			if (!visualSymbol.getSymbol().equals(new Symbol("B")))
				continue;

			Float a = visualSymbol.getSymbol().getParameter(Symbol.DISTANCE)*0.999f;			

			Shape3D box = ResourceManager.getShape3D("sponge_box");
			box.setName("Box");
			
			Matrix4f scale = new Matrix4f();
			scale.setIdentity();
			scale.setScale(a);			
			Matrix4f transform = visualSymbol.getTransform();
			transform.mul(scale);
			
			Appearance appearance = new Appearance();
			Material m = new Material();
			m.setDiffuseColor(new Color3f(1f, 1f, 0f));
			appearance.setMaterial(m);
			box.setAppearance(appearance);

			branchGroup.addChild(createTransformGroup(transform, box));
		}

		return branchGroup;
	}

	public void setRequiredParameters() {

	}

}
